﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace regextest
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            FileStream fs = new FileStream(@"C:\Users\はるか\Desktop\a.txt", FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            string org = sr.ReadToEnd();
          //  string r = "(?<=\")(\\w+):(\\S*)(?={\"|,\"|\"})";
            string r = "(\\w+)\":({\"|([^:]+)(?=,\"))";
            //////   string r = "<input type=\"hidden\"(?<token>.\\w+?)\"";
            //string r = "<input type=\"hidden\" name=\"recordId\" value=\"(\\w+)(.\\w+)(.\\w+)(.\\w+)(.\\w+)";
            ////name=\"recordId\" value=\"(\\w+?)\" />";
            ////  string regex = @""\<a class=\"small-btn\" href="[^\"]{1,200}\"";
            MatchCollection match = Regex.Matches(org, r);
            int a = match.Count;
            ////string regex = @"name=(\w+)age=(\d{0,2})";
            ////string str = "name=小强age=23";
            ////Match match = Regex.Match(str, regex);

            //richTextBox1.Text += match.Groups[1].Value;
            //richTextBox1.Text += match.Groups[2].Value;
            //richTextBox1.Text += match.Groups[3].Value;
            //richTextBox1.Text += match.Groups[4].Value;
            //richTextBox1.Text += match.Groups[5].Value;
            //            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            //            string lingpaigeturl = "https://gw.open.1688.com/openapi/http/1/system.oauth2/getToken/1009066?grant_type=authorization_code&need_refresh_token=true";
            //           HttpWebRequest http23 = WebRequest.Create(lingpaigeturl) as HttpWebRequest;
            //          // http23.ServicePoint.Expect100Continue = false;
            //           //http23.Referer = lingpaigeturl;
            //           http23.Headers.Add("Content-Language-Type", "zh_CN");
            //           http23.Method = "POST";

            //           //http23.Headers.Add("Content-Type", "text/html; charset=UTF-8");
            //           http23.ContentType = "text/html; charset=UTF-8";

            //           http23.AllowAutoRedirect = true;
            //          // http23.Credentials = System.Net.CredentialCache.DefaultCredentials;
            //           http23.KeepAlive = true;
            //           http23.ProtocolVersion = HttpVersion.Version11;
            //          // http23.CookieContainer = MyCookieContainer;
            //           string postBody = "&client_id=cbwang505&client_secret=aiN+~i~ab4_p&redirect_uri=http://gw.open.1688.com/auth/authCode.htm&code=c04ff1bf-d9c8-491b-a338-860e68356792";
            //           byte[] postData = Encoding.Default.GetBytes(postBody);
            //           http23.ContentLength = postData.Length;
            //           using (Stream request2 = http23.GetRequestStream())
            //           {
            //               try
            //               {
            //                    request2.Write(postData, 0, postData.Length);
            //               }
            //               catch
            //               {
            //                   throw;
            //               }
            //               finally
            //               {
            //                   request2.Close();
            //               }
            //           }

            //           try
            //{
            //    Stream response12 = http23.GetResponse().GetResponseStream(); 
            //                   StreamReader reader12 = new StreamReader(response12);
            //                   richTextBox1.Text += "你获取的令牌返回是:" + reader12.ReadToEnd().ToString();
            //}
            //catch (System.Exception ex)
            //{
            //    throw (ex);
            //}







            //       }

            //       private bool CheckValidationResult(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors sslPolicyErrors)
            //       {
            //           //throw new NotImplementedException();
            //           return true;
            //       }
        }
    }
}
